package com.cinema.web;

import com.cinema.entity.Ordering;
import com.cinema.entity.User;
import com.cinema.service.FilmService;
import com.cinema.service.HallService;
import com.cinema.service.OrderService;
import com.cinema.service.SeatService;
import com.cinema.util.HttpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@RequestMapping(value = "/order")
@Controller
public class OrderController {

    @Autowired
    private OrderService orderService;
    @Autowired
    private HallService hallService;
    @Autowired
    private FilmService filmService;
    @Autowired
    private SeatService seatService;
    @RequestMapping(value = "/getorderlist")
    @ResponseBody
    //或取订单列表
    private Map<String,Object> getOrderList(HttpServletRequest request){

        Map<String,Object> modelMap = new HashMap<>();
        List<Ordering> orderingList = new ArrayList<>();
        //从session中获取用户id
        int userId = (int) request.getSession().getAttribute("userId");
        //判断用户是否存在
        if (userId > 0){
            //获取订单列表
            orderingList = orderService.selectOrder(userId);
            //判断订单是否存在
            if (orderingList.size() > 0){
                modelMap.put("success",true);
                modelMap.put("orderingList",orderingList);
            }else {
                modelMap.put("success",false);
                modelMap.put("errMsg","没有你的订单信息");
            }
        }else {
            modelMap.put("success",false);
            modelMap.put("errMsg","没有此用户");
        }
        return modelMap;
    }
    @RequestMapping(value = "/delete")
    @ResponseBody
    //通过userId删除订单
    private Map<String,Object> deleteOrder(HttpServletRequest request){
        Map<String,Object> modelMap = new HashMap<>();
        int effectedNum = orderService.deleteOrder((int)request.getSession().getAttribute("userId"));
        if (effectedNum > 0){
            modelMap.put("success",true);
        }else {
            System.out.println(111);
        }
        return modelMap;
    }
}
